home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Run Magazine ReRun 1989 Special Issue
/
rerun-1989-special-issue.d64
/
irq source#7
< prev
next >
Wrap
Text File
|
2022-09-20
|
4KB
|
97 lines
;MODIFIED FLYING BALLS - BOUNCING BALLS
;WITH RASTER COMPARE GENERATED INTERRUPT
;AND SPRITE TO FOREGROUND COLLISION DETECTION
;
EXP
LDA #$1B ;Initialize VIC-II registers
STA $D011 ;Control Register - 8th bit of
;Raster Compare
LDA #0
STA $D012 ;Raster Compare Register
LDA #$03
STA $D01A ;Interrupt Enable - ERST and EMBC
STA $DC0D ;Turn off Timer A interrupt from CIA 1
RTS
ICHECK
LDA $D019 ;Get Interrupt Flag Register
AND #$02 ;Check if IMBC has occurred
BNE COLLISION ;If YES - then go to collision routine
LDA #$01 ;If NO - Turn off Raster Compare Latch
STA $D019
LDA $D01F ;Clear Sprite - Foreground
;Collision Register
JMP CONT ;Jump to ball animation routine
COLLISION
LDA $D01F ;Get Sprite to Foreground
;Collision Register
LDY #$07 ;Set Y to 7 - Sprite Number Pointer
LDX #$00 ;Set X to 0 - Sprite Collision Pointer
SHIFT
ASL ;Check if collision occurred
;with Sprite Y
BCC NOCOLL ;If NO - try next Sprite
PHA ;If YES -
TYA
STA CSPRITE,X ;Save Sprite Number
PLA
INX ;Increment Sprite Collision Pointer
NOCOLL
DEY ;Decrement Sprite Number Pointer
BPL SHIFT ;If not all sprites checked,
;do next one
DEX ;Point to last sprite
;collision detected
NEXTA
LDA CSPRITE,X ;Get Sprite Number
TAY ;Put SN in Y
PHA ;Save SN to the Stack
LDA MASK,Y ;Get MSB mask for Sprite
STA $FE ;Store in zero page location $FE
PLA ;Get SN back off stack
ASL ;Multiply by 2
TAY ;Put new pointer in Y
LDA $D000,Y ;Get X location of Sprite
PHA ;Save to the Stack
CMP #$1C ;Check if collision is at left border
BCS NOTLEFT ;If not check right side
LDA $FE ;Get MSB mask - Check MSB
;Register to make
AND $D010 ;sure Sprite is at the left side
BNE NOTLEFT ;If NO then check right side
LDA #0 ;Change X direction of Sprite
STA SD,Y ;Save to Sprite Direction data
NOTLEFT
PLA ;Get X location back from stack
CMP #$3D ;Check if at right border
BCC NOTRIGHT ;If NO - check top of screen
LDA $FE ;Get MSB mask
AND $D010 ;Check MSB bit
BEQ NOTRIGHT ;If not at right - check top of screen
LDA #$80 ;Change X direction of Sprite
STA SD,Y ;Save to Sprite Direction data
NOTRIGHT
INY ;Point to Y value of Sprite Location
LDA $D000,Y ;Get Y value of Sprite Location
CMP #$35 ;Check if at top border
BCS NOTTOP ;If NO - then check bottom of screen
LDA #0 ;Change Sprite Y Direction
STA SD,Y
NOTTOP
CMP #$E2 ;Check if at bottom border
BCC NOTBOTTOM ;If NO - Leave
LDA #$80 ;Change Sprite Y Direction
STA SD,Y
NOTBOTTOM
DEX ;Decrement Sprite Collision Pointer
BPL NEXTA ;If more sprites - Check next sprite
LDA #$02 ;Clear Sprite to Foreground
;Interrupt Latch
STA $D019
JMP $EA81 ;Jump to KERNAL IRQ exit routine
CSPRITE
.BYTE 0 0 0 0 0 0 0 0 ;Sprites that collided
MASK
.BYTE 1 2 4 8 16 32 64 128 ;Mask values